<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>内置对象</title>
</head>

<body>
    <script>
        /*
        alert();
        prompt();
        setTimeout(fn, time);
        setInterval(fn, time);
        */

        /*
        setTimeout(function () {
            console.log("2");
        }, 1000);
        */

        /*
        setTimeout(function (dog, cat, you) {
            console.log(dog);
            console.log(cat);
            console.log(you);
            console.log(arguments);
        }, 2000, "牛排", "羊排", "烤鱼", "牛蛙");
        */

        /*
        用定时器实现,2s后调用下面的函数 传递的实际参数为100,200
        */
        /*
        function add(a, b) {
            console.log(a + b);
        }
        setTimeout(add, 2000, 100, 200);
        */


        /*
        let st = setTimeout(function () {
            console.log("2");
        }, 2000);
        clearTimeout(st);//清除定时器 */


        /*
        let si = setInterval(function () {
            console.log("我会重复打印");
        }, 1000);
        clearInterval(si);//清除定时器
        */


        /*
        setTimeout(function () {
            console.log("a");
        }, 0);
        console.log("b");
        */
        //b,a

        /*
        let safeNum = Math.pow(2, 53);//2^53
        console.log(safeNum);
        let a = Math.round(0.6);
        //四舍五入
        let b = Math.ceil(0.6);
        //向上取整
        let c = Math.floor(0.6);
        //向下取整
        console.log(a, b, c);
        //1,1,0
        let ab = Math.abs(-8);
        //绝对值
        console.log(ab);
        //-8
        let myMax = Math.max(1, 2, 3);//求最大值
        console.log(myMax);
        Math.min(1, 2, 3);//求最小值
        setInterval(function () {
            console.log(Math.random());//产生随机数[0,1]
        }, 1000);
        console.log(Math.PI);
        //圆周率
        console.log(Math.E);
        //e
        console.log(Math.sqrt(5));
        //平方根
        console.log(Math.pow(8, 1 / 3));
        //立方根
        console.log(Math.sin(90));
        console.log(Math.log(Math.E));
        //1
        //问e的多少次方等于E
        console.log(Math.exp(3));
        //e^3
        */

        //产生一定范围内的随机整数
        //[n,m] [2,5]
        /*
        function myRandom(min, max) {
            console.log(Math.floor(Math.random() * (max - min - 1) + min + 1));
        }
        setInterval(myRandom, 1000, 2, 5);
        */

        /*
        let d1 = new Date();
        let d2 = new Date(毫秒数);
        let d3 = new Date(dateString);
        let d4 = new Date(year, month, day, hours, miutes, seconds, millisceonds);
        //年,月,日,小时,分钟,秒钟,毫秒 */

        /*
        let d1 = new Date();
        let d2 = new Date(2022, 7, 5, 11, 33, 0);
        let d3 = new Date("2022 03 16 12:12");
        //可以用空格隔开年月日,但是时间必须用;隔开
        let d4 = new Date(2022, 7, 15);
        console.log(d1);
        console.log(d2);
        console.log(d3);
        console.log(d4);
        */

        /*
        let date = new Date();
        console.log(date);
        //获取年份
        console.log("获取年份", date.getFullYear());
        //数字2022

        //获取月份 0~11
        console.log("获取月份", date.getMonth());
        //数字3

        //获取当前日(1~31)
        console.log("获取日", date.getDate());
        //数字10

        //获取周几
        console.log("获取周几", date.getDay());
        //获取数字0(0是周日)
        //获取范围(0-6)

        //获取小时
        console.log("获取小时", date.getHours());
        //数字21

        //获取分钟
        console.log("获取分钟", date.getMinutes());
        //数字21

        //获取秒
        console.log("获取秒", date.getSeconds());
        //数字12

        //获取好描述,1970-01-01至今
        console.log("获取毫秒数", date.getTime());
        //数字1649597013765
        */

        /*
        let date = new Date();
        console.log(date, date.toString());
        //'Sun Apr 10 2022 21:31:07 GMT+0800 (中国标准时间)'
        */

        /*
        let c1 = Date();
        //返回一个字符串从，没有getDate等方法,内容为当前时间
        let c2 = new Date();
        //返回一个日期对象,可以有getDate等方法，内容为当前时间
        let c3 = Date("2022-1-1");
        //返回当前时间，不受参数影响
        let c4 = new Date("2022-1-1");
        //返回一个日期对象，可以有getDate等方法,可以传参 内容为2022元旦
        console.log(c1);
        console.log(c2);
        console.log(c3);
        console.log(c4);
        */

        /*
        let timestamp = 1527521052;
        let date = new Date();
        console.log(date.toDateString());
        //Sun Apr 10 2022
        console.log(date.toGMTString());
        //Sun, 10 Apr 2022 13:44:19 GMT
        console.log(date.toISOString());
        //2022-04-10T13:45:09.289Z
        console.log(date.toJSON());
        //2022-04-10T13:45:35.294Z
        console.log(date.toLocaleDateString());
        //2022/4/10
        console.log(date.toLocaleString());
        //2022/4/10 21:46:37
        console.log(date.toLocaleTimeString());
        //21:47:00
        console.log(date.toTimeString());
        //21:47:47 GMT+0800 (中国标准时间)
        console.log(date.toUTCString());
        //Sun, 10 Apr 2022 13:48:11 GMT(国外时间)
        */

        //1647418072479
        /*
        function dateFormat(t) {
            let date = new Date(t);
            let year = date.getFullYear();//年费
            let month = date.getMonth + 1;//月份

            //封装一个补0函数
            function checkzero(num) {
                if (num < 10) {
                    return num = "0";
                } else {
                    return num
                }
                return (num = num < 10 ? "0" + num : num)
            }
        }
        function checkzero(num) {
            if (num < 10) {
                return num = "0" + num;
            } else {
                return num
            }
            return (num = num < 10 ? "0" + num : num);
        }
        console.log(checkzero(1));
        */


        function dateFormat(t) {
            let date = new Date(t);
            let year = date.getFullYear(); //年份
            let month = date.getMonth() + 1; //月份
            let day = checkZero(date.getDate()); //日
            let h = checkZero(date.getHours()); //小时
            let m = checkZero(date.getMinutes()); //分
            let s = checkZero(date.getSeconds()); //秒
            return `${year}年${month}月${day}日 ${h}:${m}:${s}`;
            //封装一个补0函数
            function checkZero(num) {
                return (num = num < 10 ? "0" + num : num);
            }
        }
        console.log(dateFormat(1647418072479)); //2022年3月16日 16:07:52

    </script>
</body>

</html>